package com.extension.company.view.H5;

import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.extension.company.admin.R;
import com.extension.company.common.mvc.BaseTitleActivity;

import butterknife.BindView;

/**
 * 首页的四个广告业
 */
public class HomeAdListActivity extends BaseTitleActivity {
	@BindView(R.id.ad_webview)
	WebView webView;
	private WebSettings settings;

	@Override
	public int getMainLayout() {
		return R.layout.activity_home_ad_list;
	}

	@Override
	public void initView() {
		setTitle("精品活动");
		updateSuccessView();
		settings = webView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setSupportZoom(false);
		settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		settings.setDefaultTextEncodingName("utf-8");
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // 让webView 可以加载http 和https
			webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
		}
		webView.setWebViewClient(new myWebClient());
		webView.setWebChromeClient(new myWebChrome());
		webView.addJavascriptInterface(new JS2NativeInterface(this), "JS2Native");
	}

	@Override
	public void initData() {
		String url = getIntent().getStringExtra("url");
		if (!TextUtils.isEmpty(url)) {
			webView.loadUrl(url);
		}
	}

	@Override
	public void initListener() {

	}

	private class myWebClient extends WebViewClient {

	}

	private class myWebChrome extends WebChromeClient {

	}

	@Override
	protected void onDestroy() {
		if (null != webView) {
			webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
			webView.clearHistory();
		}
		super.onDestroy();
	}
}
